"""This is a fairly buggy attempt at a tit-for-tat algorithm, which was
more trouble than it's worth due to the anonymity of opponents."""


reputation_denom = 0 #the denominator of my reputation score, i.e. the total number of h/s decisions = sum of P(t)
responses = {} #dictionary of what they did to me last round,
               #sorted by what their reputation could be. I know it's messy.
size = 0
opponent_hunts = []

def hunt_choices(round_number, current_food, current_reputation, m, player_reputations):

    global reputation_denom, size, opponent_hunts
    
    size = len(player_reputations) # = P-1

    opponent_hunts = [r*reputation_denom for r in player_reputations] #how many times they've hunted
                                                                      #is their reputation times the maximum number of times hunted
    
    hunt_decisions = []

    if round_number < 12: #establish a medium-high reputation in the first few rounds
        if round_number < 7 or round_number > 9:
            hunt_decisions = ["h" for x in player_reputations]
        else:
            hunt_decisions = ["s" for x in player_reputations]
            
    else:
        for p in opponent_hunts:

            if p/reputation_denom < .2 or p/reputation_denom > .8:
                hunt_decisions.append("s")
            else:
                if responses[p] < 0: #if it looks like bots with this reputation slacked on me last time, slack back.
                    hunt_decisions.append("s")
                else:
                    hunt_decisions.append("h")

    reputation_denom += size
       
    return hunt_decisions


def hunt_outcomes(food_earnings):

    global size, responses, reputation_denom


    for i in range(reputation_denom+size+1):
        responses[i] = 0
        
    for i in range(size):
        for z in range(size):
            
            if food_earnings[i] < 0: responses[opponent_hunts[i]+z] -= 1 #they slacked. Their total hunts next time will increase by up to size

            if food_earnings[i] > -1: responses[opponent_hunts[i]+z+1] += 1 #they hunted


def round_end(award, m, number_hunters):

    pass
